<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>bufferedviewportsizemonitor_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_dom_bufferedviewportsizemonitor_test.js.html">bufferedviewportsizemonitor_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Tests for goog.dom.BufferedViewportSizeMonitor
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>/** @suppress {extraProvide} */
<a name="line22"></a>goog.provide(&#39;goog.dom.BufferedViewportSizeMonitorTest&#39;);
<a name="line23"></a>
<a name="line24"></a>goog.require(&#39;goog.dom.BufferedViewportSizeMonitor&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.ViewportSizeMonitor&#39;);
<a name="line26"></a>goog.require(&#39;goog.events&#39;);
<a name="line27"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line28"></a>goog.require(&#39;goog.math.Size&#39;);
<a name="line29"></a>goog.require(&#39;goog.testing.MockClock&#39;);
<a name="line30"></a>goog.require(&#39;goog.testing.events&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.events.Event&#39;);
<a name="line32"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line33"></a>
<a name="line34"></a>goog.setTestOnly(&#39;goog.dom.BufferedViewportSizeMonitorTest&#39;);
<a name="line35"></a>
<a name="line36"></a>var RESIZE_DELAY = goog.dom.BufferedViewportSizeMonitor.RESIZE_EVENT_DELAY_MS_;
<a name="line37"></a>var INITIAL_SIZE = new goog.math.Size(111, 111);
<a name="line38"></a>
<a name="line39"></a>var mockControl;
<a name="line40"></a>var viewportSizeMonitor;
<a name="line41"></a>var bufferedVsm;
<a name="line42"></a>var timer = new goog.testing.MockClock();
<a name="line43"></a>var resizeEventCount = 0;
<a name="line44"></a>var size;
<a name="line45"></a>
<a name="line46"></a>var resizeCallback = function() {
<a name="line47"></a>  resizeEventCount++;
<a name="line48"></a>};
<a name="line49"></a>
<a name="line50"></a>function setUp() {
<a name="line51"></a>  timer.install();
<a name="line52"></a>
<a name="line53"></a>  size = INITIAL_SIZE;
<a name="line54"></a>  viewportSizeMonitor = new goog.dom.ViewportSizeMonitor();
<a name="line55"></a>  viewportSizeMonitor.getSize = function() { return size; };
<a name="line56"></a>  bufferedVsm = new goog.dom.BufferedViewportSizeMonitor(viewportSizeMonitor);
<a name="line57"></a>
<a name="line58"></a>  goog.events.listen(bufferedVsm, goog.events.EventType.RESIZE, resizeCallback);
<a name="line59"></a>}
<a name="line60"></a>
<a name="line61"></a>function tearDown() {
<a name="line62"></a>  goog.events.unlisten(
<a name="line63"></a>      bufferedVsm, goog.events.EventType.RESIZE, resizeCallback);
<a name="line64"></a>  resizeEventCount = 0;
<a name="line65"></a>  timer.uninstall();
<a name="line66"></a>}
<a name="line67"></a>
<a name="line68"></a>function testInitialSizes() {
<a name="line69"></a>  assertTrue(goog.math.Size.equals(INITIAL_SIZE, bufferedVsm.getSize()));
<a name="line70"></a>}
<a name="line71"></a>
<a name="line72"></a>function testWindowResize() {
<a name="line73"></a>  assertEquals(0, resizeEventCount);
<a name="line74"></a>  resize(100, 100);
<a name="line75"></a>  timer.tick(RESIZE_DELAY - 1);
<a name="line76"></a>  assertEquals(
<a name="line77"></a>      &#39;No resize expected before the delay is fired&#39;, 0, resizeEventCount);
<a name="line78"></a>  timer.tick(1);
<a name="line79"></a>  assertEquals(&#39;Expected resize after delay&#39;, 1, resizeEventCount);
<a name="line80"></a>  assertTrue(goog.math.Size.equals(
<a name="line81"></a>      new goog.math.Size(100, 100), bufferedVsm.getSize()));
<a name="line82"></a>}
<a name="line83"></a>
<a name="line84"></a>function testWindowResize_eventBatching() {
<a name="line85"></a>  assertEquals(&#39;No resize calls expected before resize events&#39;,
<a name="line86"></a>      0, resizeEventCount);
<a name="line87"></a>  resize(100, 100);
<a name="line88"></a>  timer.tick(RESIZE_DELAY - 1);
<a name="line89"></a>  resize(200, 200);
<a name="line90"></a>  assertEquals(
<a name="line91"></a>      &#39;No resize expected before the delay is fired&#39;, 0, resizeEventCount);
<a name="line92"></a>  timer.tick(1);
<a name="line93"></a>  assertEquals(
<a name="line94"></a>      &#39;No resize expected when delay is restarted&#39;, 0, resizeEventCount);
<a name="line95"></a>  timer.tick(RESIZE_DELAY);
<a name="line96"></a>  assertEquals(&#39;Expected resize after delay&#39;, 1, resizeEventCount);
<a name="line97"></a>}
<a name="line98"></a>
<a name="line99"></a>function testWindowResize_noChange() {
<a name="line100"></a>  resize(100, 100);
<a name="line101"></a>  timer.tick(RESIZE_DELAY);
<a name="line102"></a>  assertEquals(1, resizeEventCount);
<a name="line103"></a>  resize(100, 100);
<a name="line104"></a>  timer.tick(RESIZE_DELAY);
<a name="line105"></a>  assertEquals(
<a name="line106"></a>      &#39;No resize expected when size doesn\&#39;t change&#39;, 1, resizeEventCount);
<a name="line107"></a>  assertTrue(goog.math.Size.equals(
<a name="line108"></a>      new goog.math.Size(100, 100), bufferedVsm.getSize()));
<a name="line109"></a>}
<a name="line110"></a>
<a name="line111"></a>function testWindowResize_previousSize() {
<a name="line112"></a>  resize(100, 100);
<a name="line113"></a>  timer.tick(RESIZE_DELAY);
<a name="line114"></a>  assertEquals(1, resizeEventCount);
<a name="line115"></a>  assertTrue(goog.math.Size.equals(
<a name="line116"></a>      new goog.math.Size(100, 100), bufferedVsm.getSize()));
<a name="line117"></a>
<a name="line118"></a>  resize(200, 200);
<a name="line119"></a>  timer.tick(RESIZE_DELAY);
<a name="line120"></a>  assertEquals(2, resizeEventCount);
<a name="line121"></a>  assertTrue(goog.math.Size.equals(
<a name="line122"></a>      new goog.math.Size(200, 200), bufferedVsm.getSize()));
<a name="line123"></a>}
<a name="line124"></a>
<a name="line125"></a>function resize(width, height) {
<a name="line126"></a>  size = new goog.math.Size(width, height);
<a name="line127"></a>  goog.testing.events.fireBrowserEvent(
<a name="line128"></a>      new goog.testing.events.Event(
<a name="line129"></a>          goog.events.EventType.RESIZE, viewportSizeMonitor));
<a name="line130"></a>}
</pre>


</body>
</html>
